﻿using System;
using System.Data;

namespace Dapper.Library
{
    /// <summary>
    /// 查询集合
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class QuerySql<T> : Aggregation<T>, IQuerySql<T>
    {
        public QuerySql(IDbConnection conn, SqlProvider sqlProvider) : base(conn, sqlProvider)
        {
            SqlProvider.SetContext.TableType = typeof(T);
        }

        public QuerySql(IDbConnection conn, SqlProvider sqlProvider, IDbTransaction dbTransaction) : base(conn, sqlProvider, dbTransaction)
        {
            SqlProvider.SetContext.TableType = typeof(T);
        }

        internal QuerySql(IDbConnection conn, SqlProvider sqlProvider, Type tableType, IDbTransaction dbTransaction) : base(conn, sqlProvider, dbTransaction)
        {
            SqlProvider.SetContext.TableType = tableType;
        }

        /// <summary>
        /// 使用SQL执行查询语句
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public QuerySql<T> BySql(string predicate, object parameter)
        {
            SqlProvider.SetContext.SqlString = predicate;
            SqlProvider.SetContext.Params = parameter;
            return this;
        }
    }
}
